import erniebot.utils

def calc_tokens(messages):
    tokens = 0
    for message in messages:
        tokens += erniebot.utils.token_helper.approx_num_tokens(message.content)
        tokens += 2  # 空格+user
    return tokens
        